function Solve(params)
{
    var firstRow = params[0].split(' ').map(Number),
        position = params[1].split(' ').map(Number),
        jumps = new Array(firstRow[2]);

    for (var i = 0; i < jumps.length; i++)
    {
        jumps[i] = params[i + 2].split(' ').map(Number);
    }

    var field = new Array(firstRow[0]);

    for (var i = 0; i < field.length; i++)
    {
        field[i] = new Array(firstRow[1]);
    }

    var stepper = 0;

    for (var rows = 0; rows < field.length; rows++)
    {
        for (var columns = 0; columns < field[0].length; columns++)
        {
            stepper++;
            field[rows][columns] = stepper;
        }
    }

    var sum = 0;
    var steps = 0;

    for (var i = 0; i < jumps.length; i++)
    {
        if (position[0] >= field.length || position[1] >= field[0].length)
        {
            return "escaped " + sum;
        }

        if (field[position[0]][position[1]] === 0)
        {
            return "caught " + steps;
        }

        sum += field[position[0]][position[1]];
        field[position[0]][position[1]] = 0;
        position[0] += jumps[i][0];
        position[1] += jumps[i][1];
        steps++;

        if (i === jumps.length - 1)
        {
            i = -1;
        }
    }
}

var input = [
    '6 7 3',
    '0 0',
    '2 2',
    '-2 2',
    '3 -1'
];

console.log(Solve(input));